package com.hong.spring.config;

import org.zeromq.SocketType;
import org.zeromq.ZMQ;

/**
 * @author: csh
 * @Date: 2021/4/27 18:06
 * @Description:zero配置
 */
public class ZeroMqProducer {

    private ZMQ.Socket push;
    private Integer threads;
    private SocketType zmqType;
    private String addr;

    public ZeroMqProducer(Integer threads, SocketType zmqType, String addr) {
        this.threads = threads;
        this.zmqType = zmqType;
        this.addr = addr;
    }

    public ZMQ.Socket init(){
        ZMQ.Context context = ZMQ.context(threads);
        push = context.socket(zmqType);
        push.bind(addr);
        return  push;
    }

    /**
     *
     * 功能描述: 发送消息
     *
     * @param:
     * @return:
     * @auther: csh
     * @date: 2021/4/28 17:05
     */
    public Boolean send(String msg){
        return push.send(msg,ZMQ.NOBLOCK);
    }



}
